<div id="tb<?php echo $uniqid;?>" style="padding:5px">
	<table cellspacing="0" cellpadding="0">
		<tbody>
		<tr>
			<td><a href="javascript:void(0);" onclick="tuikelevelAdd();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-tianjia1"></i><span class="l-btn-text">增加</span></span></a></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td><a href="javascript:void(0);" onclick="tuikelevelEdit();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-bianji"></i><span class="l-btn-text">编辑</span></span></a></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td><a href="javascript:void(0);" onclick="tuikelevelDelete();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shanchu"></i><span class="l-btn-text">删除</span></span></a></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td><a href="javascript:void(0);" onclick="tuikelevelReload();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重载</span></span></a></td>
			<td>&nbsp&nbsp;<input id="tuikelevelKeywords" style="width:100px" type="text"
								  class="easyui-input textbox"></td>
			<td><a href="javascript:void(0);" onclick="tuikelevelSearch();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">查询</span></span></a></td>
		</tr>
		</tbody>
	</table>
</div>
<div class="con"  style="-moz-user-select:none;">
	<table id="tuikelevel"></table>
</div>
<div id="tuikelevelDlg" class="easyui-dialog" style="width:720px; height:520px;" title="信息框" closed="true"></div>
<script>
	var tuikelevelAdd = function () {
		$("#tuikelevelDlg").dialog({
			title: '新增信息',
			closed: false,
			width: 740,
			height: 520,
			cache: false,
			href: '/admin/tuikelevel/add',
			modal: true,
			buttons: [{
				text: '保存',
				id: 'tuikelevelsubmit',
				iconCls: 'icon-ok',
			}, {
				text: '关闭',
				iconCls: 'icon-no',
				handler: function () {
					$("#tuikelevelDlg").dialog('close');
				}
			}]
		});
	};
	var tuikelevelEdit = function (id) {
		let rowId = id || ($('#tuikelevel').datagrid('getSelected') && $('#tuikelevel').datagrid('getSelected').level);
		if (rowId) {
			$("#tuikelevelDlg").dialog({
				title: '编辑信息',
				closed: false,
				width: 740,
				height: 520,
				cache: false,
				href: '/admin/tuikelevel/edit?level=' + rowId,
				modal: true,
				buttons: [{
					text: '保存',
					id: 'tuikelevelsubmit',
					iconCls: 'icon-ok',
				}, {
					text: '关闭',
					iconCls: 'icon-no',
					handler: function () {
						$("#tuikelevelDlg").dialog('close');
					}
				}]
			});
		} else {
			$.messager.alert('提示', '请先选择要编辑的行！', 'warning');
		}
	};
	var tuikelevelDelete = function (id) {
		let rowId = id || ($('#tuikelevel').datagrid('getSelected') && $('#tuikelevel').datagrid('getSelected').level);
		if (rowId) {
			$.messager.confirm('提示', '确定删除吗？', function (r) {
				if (r) {
					$.messager.progress();
					$.post('/admin/tuikelevel/delete', {level: rowId}, function (data) {
						$.messager.progress('close');
						if (data.ret === 0) {
							$.messager.show({
								title: '提示',
								msg: data.msg,
								timeout: 3000,
								showType: 'slide'
							});
							tuikelevelReload();
						} else {
							$.messager.alert('提示', data.msg, 'warning');
						}
					}, 'json');
				}
			});
		} else {
			$.messager.alert('提示', '请先选择要删除的行！', 'warning');
		}
	};
	var tuikelevelReload = function () {
		$("#tuikelevel").datagrid('reload');
	};
	var tuikelevelSearch = function () {
		var height = $(window).height() - $(".top").height() - 46;
		var width = $(window).width() - $(".leftmenu").width() - 8;
		$("#tuikelevel").datagrid({
			title: '等级列表',
			width: width,
			height: height,//高度
			singleSelect: true,//如果为true，则只允许选择一行
			striped: true,//是否显示斑马线效果。
			rownumbers: true,//如果为true，则显示一个行号列。
			pagination: true,//是否显示分页
			pageSize: 10,
			pageList: [10, 15, 20, 25],
			method: 'post',
			sortName: 'level',
			sortOrder: 'asc',
			idField: 'level',
			treeField: 'title',
			url: '/admin/tuikelevel/index',
			queryParams: {keywords: $('#tuikelevelSearch').val()},
			fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
			nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
			selectOnCheck: false,
			checkOnSelect: true,
			toolbar: '#tb<?php echo $uniqid;?>',
			columns: [[
				{field:'level',title:'等级',width:fixWidth(10),formatter:function (value,rowData,rowIndex){
						return '等级' + (rowIndex + 1);
					}},
				{field:'name',title:'等级名称',width:fixWidth(20)},
				{field:'image',title:'徽章',width:fixWidth(20),formatter:function (value,rowData,rowIndex){
						return value ? "<img height='50px' src='"+value+"'>" : '';
					}},
				{field:'award_zhitui',title:'直推佣金比例',width:fixWidth(10),formatter:function (value,rowData,rowIndex){
						return value+'%';
					}},
				{field:'award_jiantui',title:'间推佣金比例',width:fixWidth(10),formatter:function (value,rowData,rowIndex){
						return value+'%';
					}},
				{
					field: 'options', title: '操作', align:'center', width: fixWidth(15), formatter: function (value, rowData, rowIndex) {
						let buttons = '<div class="table"><span class="l-btn l-btn-small color9 table" onclick="tuikelevelEdit(\'' + rowData.level + '\')"><span class="l-btn-text">修改</span></span>';
						buttons += '<span class="l-btn l-btn-small color9 table" onclick="tuikelevelDelete(\'' + rowData.level + '\')"><span class="l-btn-text">删除</span></span>';
						return buttons + '</div>';
					}
				},
			]],
			onDblClickRow: function (index, field) {
				tuikelevelEdit();
			}
		});
	};
	onDatagridResize("#tuikelevel");
	tuikelevelSearch();
</script>
